/*
提供统一的硬件定时器API
中断入口统一在ISR.C中
*/

#ifndef _MCU_TIMER_H_
#define _MCU_TIMER_H_

#include "mcu.h"



#define TIM0_VALUE (TIM0_CYCLE * 1000l * F_SYS / 12) // TIM0_CYCLE计时需要的T0时钟周期数

#if (TIM0_VALUE > 65535)
#error "T0 can not support this TIM0_CYCLE."
#elif (TIM0_VALUE > 128)
#define TH0_VALUE (u8)((65536 - TIM0_VALUE) >> 8)
#define TL0_VALUE (u8)(65536 - TIM0_VALUE)
#else
#error "TIM0_CYCLE is too short."
#endif

#define TIM2_VALUE  (TIM2_CYCLE * 1000l * F_SYS / 512)   //定时器周期需要的时钟周期数

#if (TIM2_VALUE > 65535)
#error "T2 can not support this TIM2_CYCLE."
#elif (TIM2_VALUE > 32)
#define TH2_VALUE (u8)((65536 - TIM2_VALUE) >> 8)
#define TL2_VALUE (u8)(65536 - TIM2_VALUE)
#else
#error "TIM0_CYCLE is too short."
#endif





void Tim0_Init();

// TIM0手动重装载
void Tim0_ReLoad();

#define Tim0_GetCycleValue()    (u16)TIM0_VALUE
u16 Tim0_GetNowValue();      

void Tim2_Init();


#endif



